﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class AddMobileDetailDAL
    {

        #region[AddMobileDetail_SelectALL]
        public List<DTO.AddMobileDetailDTO> AddMobileDetail_SelectALL()
        {
            List<DTO.AddMobileDetailDTO> amdall = new List<DTO.AddMobileDetailDTO>();
            
            Connection connecttion = new Connection();
            MySqlConnection con = new MySqlConnection(connecttion.Connect);
            MySqlCommand cmd = new MySqlCommand("SelectAllAddMobileDetail", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            con.Open();
            MySqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                DTO.AddMobileDetailDTO amd = new DTO.AddMobileDetailDTO();
                amd.AddMobileID = dr.GetInt32(0);
                amd.MobileID = dr.GetInt32(1);
                amd.PrizeAdd = dr.GetInt32(2);
                amd.Number = dr.GetInt32(3);
                amd.AddID = dr.GetInt32(4);
                amdall.Add(amd);
            }
            dr.Close();
            con.Close();

            return amdall;
        }
        #endregion

        #region [AddMobileDetail_Insert]
        public bool AddMobileDetail_Insert(DTO.AddMobileDetailDTO amd)
        {
            Connection connecttion = new Connection();
            MySqlConnection con = new MySqlConnection(connecttion.Connect);
            MySqlCommand cmd = new MySqlCommand("AddAddMobileDetail", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add(new MySqlParameter("@mobileid", amd.MobileID));
            cmd.Parameters.Add(new MySqlParameter("@prizeadd", amd.PrizeAdd));
            cmd.Parameters.Add(new MySqlParameter("@number", amd.Number));
            cmd.Parameters.Add(new MySqlParameter("@addid", amd.AddID));

            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            return true;
        }
        #endregion

    }
}
